import { BasicColumn, FormSchema } from '/@/components/Table';
import { render } from '/@/utils/common/renderUtils';
import * as configTmplApi from '/@/api/infra/configTmpl';
import { useI18n } from '/@/hooks/web/useI18n';
import dictEnum from '/@/enums/dictEnum';
const { t } = useI18n('');

export enum ConfigStatus {
  NORMAL = 1,
  DISABLE = 2,
}

export const columns: BasicColumn[] = [
  {
    title: t('名称'),
    dataIndex: 'name',
    width: 100,
  },
  {
    title: t('可见范围'),
    dataIndex: 'showScope',
    width: 100,
    customRender: ({ text }) => {
      const color = "green"
      return render.renderTag(render.renderDict(text, dictEnum.SysConfigShowScope), color)
    },
  },
  {
    title: t('类型'),
    dataIndex: 'type',
    width: 100,
  },
  {
    title: t('标识'),
    dataIndex: 'configKey',
    width: 100,
  },
  {
    title: t('状态'),
    dataIndex: 'status',
    width: 100,
    customRender: ({ text }) => {
      const color = text == "2" ? "red" : "green"
      return render.renderTag(render.renderDict(text, dictEnum.SysConfigStatus), color)
    },
  },
  {
    title: t('更新时间'),
    dataIndex: 'updatedAt',
    width: 150,
    align: 'center',
  },
  {
    title: t('更新者'),
    dataIndex: 'updatedBy',
    width: 100,
  },
  {
    title: t('备注'),
    dataIndex: 'remark',
    width: 130,
    align: 'left',
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    label: t('名称'),
    field: 'name',
    component: 'Input',
  },
  {
    label: t('标识'),
    field: 'configKey',
    component: 'Input',
  },
  {
    label: t('类型'),
    field: 'type',
    component: 'ApiSelect',
    componentProps: {
      api: configTmplApi.listConfigType,
      showSearch: true,
      allowClear: true,
      labelField: 'label',
      valueField: 'value',
    },
  },
];

export const inputFormSchemas: FormSchema[] = [
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
  {
    label: t('配置名称'),
    required: true,
    field: 'name',
    component: 'Input',
    componentProps: {
      maxlength: 64,
    },

  },
  {
    label: t('可见范围'),
    required: true,
    field: 'showScope',
    component: "JDictSelectTag",
    helpMessage: [
      '子租户可见: 子租户、主租户、应用管理端都可见，配置会从子租户开始依次向上获取，知道获取到数据',
      '主租户可见: 主租户、应用管理端都可见，配置会从主租户开始依次向上获取，知道获取到数据',
      '应用管理端可见: 应用管理端可见，配置只会从应用管理端获取',
    ],
    componentProps: {
      dictType: dictEnum.SysConfigShowScope,
      type: 'radio',
    },
  },
  {
    label: t('配置类型'),
    required: true,
    field: 'type',
    dynamicDisabled: ({ values }) => {
      return !!values.id
    },
    component: "MyAutoComplete"
  },
  {
    label: t('配置标识'),
    required: true,
    field: 'configKey',
    component: 'Input',
    dynamicDisabled: ({ values }) => {
      return !!values.id
    },
    componentProps: {
      maxlength: 64,
    }
  },
  {
    label: "字段",
    field: "diyFormId",
    required: false,
    component: "Input",
    slot: "diyForm",
  },

  {
    label: t('状态'),
    required: true,
    field: 'status',
    component: "JDictSelectTag",
    defaultValue: 1,
    componentProps: {
      dictType: dictEnum.SysConfigStatus,
      type: 'radio',
    },

  },
  {
    label: t('备注'),
    field: 'remark',
    required: false,
    component: 'InputTextArea',
    componentProps: {
      maxlength: 500,
    },
    colProps: { lg: 24, md: 24 },
  }
];
